package org.lex.ftp.ui.bookmark;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.lex.ftp.util.FTPFileIconCache;
import org.lex.ftp.util.Resources;


public class BookmarkNodeRenderer extends DefaultTreeCellRenderer {
	private static final Icon SITE_ICON = Resources.getIcon(Resources.SITE_ICON);
	private static final Icon FOLDER_ICON = FTPFileIconCache.getInstance().getFolderIcon();

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		String text = null;
		Icon icon = null;
		if (value instanceof BookmarkTreeNode) {
			BookmarkTreeNode node = (BookmarkTreeNode) value;
			text = node.getName();
			if (null == node.getFolder())
				icon = SITE_ICON;
			else
				icon = FOLDER_ICON;
		} else {
			text = null == value ? "" : value.toString();
		}
		super.getTreeCellRendererComponent(tree, text, sel, expanded, leaf, row, hasFocus);
		this.setIcon(icon);
		return this;
	}
}
